<template>
  <div class="searchBox">
    <div class="search">
      <div class="searchLeft"></div>
      <input type="text" v-model="text" @keydown.enter="search" placeholder="一键找到你想要的">
      <div class="searchBt" @click="search()">搜索</div>
    </div>
    <div class="SearchType">
      <img class="SearchTypeCard" :src="item.image" :style="navIndex === index ?
      navBg : ''" v-for="(item,index) in SearchType" :key="index" @click="getBgcolor(index)" alt="" :title="item.name">
    </div>
  </div>
</template>

<script>
import {SearchType} from "@/config/SearchType";

export default {
  name: "SearchBox",
  data() {
    return {
      SearchType,
      navBg:"border: 2px solid white;" +
          "background-color:white;",
      text: "",
      link: SearchType[0].link,
      navIndex: 0
    }
  },
  methods: {
    getBgcolor(index) {
      this.navIndex = index;
      this.link = SearchType[index].link;
    },
    search() {
      if (this.text === "") return;
      window.open(this.link.replace('$k', this.text));
    }
  }
}
</script>

<style>
.searchBox {
  margin: auto;
  width: 80%;
  height: 230px;
}

.search {
  width: 400px;
  height: 40px;
  overflow: hidden;
  margin: 150px auto 0 auto;
  border-radius: 15px;
  background-color: #42b983;
}

.searchLeft {
  width: 16px;
  height: 40px;
  float: left;
  background-color: white;
}

.search input {
  height: 40px;
  width: 310px;
  float: left;
  font-size: 16px;
  border-style: none;
  background-color: white;
}

.searchBt {
  width: 74px;
  height: 40px;
  background-color: #FFF782;
  float: left;
  text-align: center;
  line-height: 40px;
}

.searchBt:hover {
  cursor: pointer;
}

.SearchType {
  margin: 30px auto 0 auto;
  width: 306px;
  height: 134px;
  border-radius: 10px;
  background-color: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(10px);
}

.SearchTypeCard {
  float: left;
  margin: 8px 6px 8px 6px;
  width: 45px;
  height: 45px;
  border-radius: 20px;
  border: 2px solid white;
}

.SearchTypeCard:hover {
  cursor: pointer;
  background-color: white;
}
</style>